package top.huntwolf.admin.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.huntwolf.admin.dao.HotSaleDao;
import top.huntwolf.admin.pojo.book.Book;

import java.util.ArrayList;
import java.util.List;

@Service
@EnableScheduling
@Transactional
public class ScheduledService {

    @Autowired
    private OrderService orderService;

    @Autowired
    private HotSaleDao hotSaleDao;

    @Scheduled(cron = "0 0 0 1 * ?")
    public void scheduled(){
        hotSaleDao.delete();
        List<Book> Books = orderService.searchBuyBooksAllOrderNumLastMonth();
        List<Book> bookList = new ArrayList<>();

        for(Book book : Books){
            bookList.add(book);
        }
        for(Book book : Books){
            hotSaleDao.insert(book);
        }
    }

}
